package com.wlps.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wlps.entity.Client;
import com.wlps.result.ResultPageVo;
import com.wlps.result.ResultUtils;
import com.wlps.result.ResultVo;
import com.wlps.service.IClientService;
import com.wlps.vo.ClientOrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *    客服中心模块
 * </p>
 * @author winner
 * @date 2020/8/2
 */

@Api(tags="客服中心管理")
@RestController
@Slf4j
@RequestMapping("/api/client_server")
@Valid
public class ClientServerController {
    @Resource
    ClientCenter clientCenter;

    @PostMapping("/add_client")
    @ApiOperation("添加客户信息")
    public ResultVo<Client> addClient(@ApiParam("需要添加的用户信息") @RequestBody
                                                  Client client, BindingResult bindingResult){
        clientCenter.addClient(client);
        return ResultUtils.success("客户添加成功",client);
    }
    @ApiOperation("查询客户信息===>clientInfo为id或者名称 id的话使用精确查询，名称的话使用模糊查询")
   @GetMapping("/query_client/{queryType}/{clientInfo}")
    public ResultVo<List<Client>> queryClient(@PathVariable @ApiParam("客户id或者客户名称") String queryType
            ,@PathVariable @ApiParam("客户id或者客户名称信息") String clientInfo){
        List<Client> clients = clientCenter.queryClientByRequireC(queryType, clientInfo);
        return ResultUtils.success("客户查询成功",clients);
    }
    @ApiOperation("查询客户分页信息")
    @GetMapping("/query_client_pageInfo")
    public ResultPageVo<Client> queryPageInfo(){
        return clientCenter.clientPageInfo();
    }

    @ApiOperation("更新客户信息,通过client的id")
    @PostMapping("/update_client")
    public ResultVo<Client> updateClient(@ApiParam("客户修改后的信息,通过id查询需要修改的用户") @RequestBody Client client){
        clientCenter.updateClient(client);
        return ResultUtils.success("更新用户信息成功,更新后数据",client);
    }
    @ApiOperation("删除用户信息，通过id删除client")
    @GetMapping("/delete_client/{id}")
    public ResultVo<Client> deleteClient(@PathVariable @ApiParam("客户的id") long id){
        clientCenter.removeClient(id);
        return ResultUtils.success("删除用户成功");
    }

    @ApiOperation("查询用户详情信息通过id 用户信息和用户订单详情信息 再url中添加id")
    @GetMapping("/query_client_detailInfo/{id}")
    public ResultVo<ClientOrderVo> queryClientDetailInfo(@PathVariable @ApiParam("客户id") long id){
        ClientOrderVo clientOrderVo = clientCenter.queryClientDetail(id);
        return ResultUtils.success("查询用户详情成功",clientOrderVo);
    }
}
